home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
WASTE 1.2
/
WASTE Demo ƒ
/
WEDemoInit.c
< prev
next >
Wrap
Text File
|
1996-06-17
|
4KB
|
181 lines
/*
WASTE Demo Project:
Initialization and Finalization Routines
Copyright © 1993-1996 Marco Piovanelli
All Rights Reserved
C port by John C. Daub
*/
#ifndef __DIALOGS__
#include <Dialogs.h>
#endif
#ifndef __FONTS__
#include <Fonts.h>
#endif
#ifndef __GESTALT__
#include <Gestalt.h>
#endif
#ifndef __SCRAP__
#include <Scrap.h>
#endif
#ifndef __TEXTSERVICES__
#include <TextServices.h>
#endif
#ifndef __WEDEMOAPP__
#include "WEDemoIntf.h"
#endif
#include "WEObjectHandlers.h"
OSErr Initialize( void )
{
long response;
short i;
OSErr err;
// expand the zone to its maximum size
MaxApplZone( );
// allocate some extra master pointer blocks
for ( i = 0; i < 6; i++ )
{
MoreMasters( );
}
// initialize the Toolbox
InitGraf( &qd.thePort );
InitFonts( );
InitWindows( );
InitMenus( );
TEInit( ); // tho we use WASTE for text stuff, dialogs, etc all use TextEdit so don't remove this!
InitDialogs( nil );
InitCursor( );
FlushEvents( everyEvent, 0 );
// if desk scrap is too large, unload it
if ( InfoScrap( )->scrapSize > kScrapThreshold )
{
UnloadScrap( );
}
// make sure system software versino is 7.0 or newer (classic 68K only)
#if !GENERATINGCFM
if ( ( Gestalt( gestaltSystemVersion, &response ) != noErr ) || ( response < kMinSystemVersion ) )
{
SetCursor( &qd.arrow );
response = Alert( kAlertNeedSys7, nil );
return -1;
}
#endif
// determine whether color Quickdraw is available
gHasColorQD = (Gestalt(gestaltQuickdrawVersion, &response) == noErr)
&& (response >= gestalt8BitQD);
// determine whether the Drag Manager is available
gHasDragAndDrop = (Gestalt( gestaltDragMgrAttr, &response ) == noErr )
&& BTST( response, gestaltDragMgrPresent );
#if GENERATINGCFM
// additional check needed if DragLib is weak-linked
gHasDragAndDrop = gHasDragAndDrop && (&NewDrag != nil);
#endif
// determine whether the Text Services Manager is available
gHasTextServices = ( Gestalt( gestaltTSMgrVersion, &response ) == noErr );
// register this application with the TSM
if ( gHasTextServices )
{
if ( ( err = InitTSMAwareApplication( ) ) != noErr )
goto cleanup;
}
// install default drag handlers
if ( gHasDragAndDrop )
{
if ( ( err = InstallDragHandlers( ) ) != noErr )
goto cleanup;
}
// install the sample object handlers for pictures and sounds
if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler,
(UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), nil)) != noErr)
goto cleanup;
if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler,
(UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), nil)) != noErr)
goto cleanup;
if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler,
(UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), nil)) != noErr)
goto cleanup;
if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler,
(UniversalProcPtr) NewWENewObjectProc(HandleNewSound), nil)) != noErr)
goto cleanup;
if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler,
(UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), nil)) != noErr)
goto cleanup;
if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler,
(UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), nil)) != noErr)
goto cleanup;
// perform other initialization chores
if ( ( err = InitializeEvents( ) ) != noErr )
goto cleanup;
if ( ( err = InitializeMenus( ) ) != noErr )
goto cleanup;
// clear result code
err = noErr;
cleanup:
if ( err != noErr )
{
ErrorAlert( err );
}
return err;
}
void Finalize( void )
{
// remove drag handlers
if ( gHasDragAndDrop )
{
RemoveDragHandlers( );
}
// notify text services that we're closing down
if ( gHasTextServices )
{
CloseTSMAwareApplication( );
}
}